package cn.nfwx.tv.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.animation.Animation;
import android.widget.LinearLayout;

import cn.nfwx.tv.R;
import cn.nfwx.tv.util.AnimationUtil;

/**
 * Created by zhouzechao on 2017/12/19.
 */

public class ShineImage extends LinearLayout {
    private boolean _init;
    private int mWidth;

    public ShineImage(Context context) {
        this(context, null);
    }

    public ShineImage(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ShineImage(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        init();

        _init = false;
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_shine, this);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mWidth = w;

        if (!_init) {
            _init = true;
            Animation animation = AnimationUtil.getTranslateAnimation(-mWidth / 3, mWidth / 3, 0, 0, 3000);
            animation.setRepeatCount(-1);
            findViewById(R.id.line).startAnimation(animation);
        }
    }
}
